#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int N = 1e6 + 10;
int a[N];
int d[N];
int	n;
int cnt = 1;
vector<int>g[N];
void dfs(int u)
{
	d[u]--;
	while (d[u]) {
		int v = a[++cnt];
		if (u < v)	g[u].push_back(v);
		else g[v].push_back(u);
		d[u] -= d[v];
		dfs(v);
	}
}
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 1; i <= n; i++) {
		scanf("%d", &d[i]);
	}
	dfs(a[1]);
	for (int i = 1; i <= n; i++) {
		sort(g[i].begin(), g[i].end());
	}
	for (int i = 1; i <= n; i++) {
		for (auto x : g[i]) {
			printf("%d %d\n", i, x);
		}
	}
	return 0;
}